//
//  SNThemeViewController.m
//  DayDayHappy
//
//  Created by yutao on 14-2-19.
//  Copyright (c) 2014年 yutao. All rights reserved.
//

#import "SNThemeViewController.h"
#import "SNImageModel.h"
#import "SNThemeCell.h"
#import "SNThemeItemViewController.h"
@interface SNThemeViewController ()

@end

@implementation SNThemeViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.requestUrl = [NSString stringWithFormat:@"%@%@",kBaseUrl,kGetThemeList];
//        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
//            [self.dbHelper createTableWithModelClass:[SNThemeModel class]];
//        });
        [self.dbHelper createTableWithModelClass:[SNThemeModel class]];
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
}

- (NSString *)currentType
{
    return kThemeModle;
}

- (Class)currModel
{
    return [SNThemeModel class];
}

- (SNBaseModel *)currModelWithObj:(id)obj
{
    return [[SNThemeModel alloc] initWithDictionary:obj error:nil];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellIdentif = @"cell";
    SNThemeCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentif];
    if (cell == nil) {
        cell = [[SNThemeCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentif];
    }
    
    [cell setUpImageCellWithObject:self.contentDataArray[indexPath.row] atIndexPath:indexPath];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    SNThemeItemViewController *themeItem = [[SNThemeItemViewController alloc] init];
    SNThemeModel *themeModel = (SNThemeModel *)[self.contentDataArray objectAtIndex:indexPath.row];
    themeItem.hidesBottomBarWhenPushed = YES;
    themeItem.themeId = [NSString stringWithFormat:@"%d",themeModel.theme_id];
    
    [self.navigationController pushViewController:themeItem animated:YES];
    
}

@end
